<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="学生ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="studentId">
              <a-input-number v-model="model.studentId" placeholder="请输入学生ID" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="账户ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accountId">
              <a-input-number v-model="model.accountId" placeholder="请输入账户ID" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="变更金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="changeAmount">
              <a-input-number v-model="model.changeAmount" placeholder="请输入变更金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="变更方向 0=冻结 1=增加 2=减少" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="changeDirection">
              <a-input-number v-model="model.changeDirection" placeholder="请输入变更方向 0=冻结 1=增加 2=减少" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="付款时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入付款时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="变更前金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="changeBeforeAmount">
              <a-input-number v-model="model.changeBeforeAmount" placeholder="请输入变更前金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="变更后金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="changeAfterAmount">
              <a-input-number v-model="model.changeAfterAmount" placeholder="请输入变更后金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="创建人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createName">
              <a-input v-model="model.createName" placeholder="请输入创建人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="更新人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="updateName">
              <a-input v-model="model.updateName" placeholder="请输入更新人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="删除标志，0=正常，1=删除" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isDelete">
              <a-input-number v-model="model.isDelete" placeholder="请输入删除标志，0=正常，1=删除" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="课程ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="courseId">
              <a-input-number v-model="model.courseId" placeholder="请输入课程ID" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="课程类型 1=1v1课程 2=group class" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="courseType">
              <a-input-number v-model="model.courseType" placeholder="请输入课程类型 1=1v1课程 2=group class" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="通知ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invoiceId">
              <a-input-number v-model="model.invoiceId" placeholder="请输入通知ID" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="拓展字段" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="extends">
              <a-input v-model="model.extends" placeholder="请输入拓展字段"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'AccountTransactionForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           studentId: [
              { required: true, message: '请输入学生ID!'},
           ],
           accountId: [
              { required: true, message: '请输入账户ID!'},
           ],
           changeAmount: [
              { required: true, message: '请输入变更金额!'},
           ],
           changeDirection: [
              { required: true, message: '请输入变更方向 0=冻结 1=增加 2=减少!'},
           ],
           changeBeforeAmount: [
              { required: true, message: '请输入变更前金额!'},
           ],
           changeAfterAmount: [
              { required: true, message: '请输入变更后金额!'},
           ],
           createName: [
              { required: true, message: '请输入创建人!'},
           ],
           updateName: [
              { required: true, message: '请输入更新人!'},
           ],
           isDelete: [
              { required: true, message: '请输入删除标志，0=正常，1=删除!'},
           ],
           courseType: [
              { required: true, message: '请输入课程类型 1=1v1课程 2=group class!'},
           ],
        },
        url: {
          add: "/sistersophie/accountTransaction/add",
          edit: "/sistersophie/accountTransaction/edit",
          queryById: "/sistersophie/accountTransaction/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>